<?php

namespace app\admin\controller;
use app\base\controller\Base;
use think\Request;
use think\Cache;
use think\Config;
use think\Session;

/**
 * Class Pcsite
 * @package app\admin\controller  PCsite配置
 */
class Pcsite extends Base
{
    public  $model;

    public function __construct()
    {
   $this->model = model("PcSite");
        parent::__construct();
    }


    /**
     *  pC具体设置
     *
     * @return \think\Response
     */
    public function index()
    {//
        $where = [];
        //时间的处理
        $where['p.position_key'] = $this->position_key;

        $res =   $this->model->AdminPageNoAgent($where);
        if(empty($res)){
            return failJson("暂无记录");
        }
        return   resJson(1,$this->ecLang("query"),$res['res'],$res['pageInfo']);
    }




    /**
     *  添加配置信息
     */
    public function save(){
        $data = $this->RealData;
        $siteModelPosition = new \app\admin\model\PcSitePosition();
        $resultPostion = $siteModelPosition->where("position_key",$this->position_key)->find();
        $data['position'] = $resultPostion->id;
        $resultPostionResultCount = $this->model->where("position",$resultPostion->id)->where('key',$this->key)->count();
        if($resultPostionResultCount>0){
            return failJson("同一位置 key不能重复");
        }
        unset($data['position_key']);
        $res = $this->model->save($data);
        if(empty($res)){
            return failJson("添加前台信息失敗");
        }
        return sucessJson("添加前台信息成功");
    }

    /**
     *  添加配置信息
     */
    public function up(){
        $data = $this->RealData;
        unset($data['key']);
     /*   $siteModelPosition = new \app\admin\model\PcSite();
        $resultPostionResultCount = $siteModelPosition->where("key",$this->key)->whereOr("id",$this->id)->count();
        if($resultPostionResultCount>1){
            return failJson("同一位置 key不能重复");
        }*/
        $res = $this->model->save($data,['id'=>$this->RealData['id']]);
        if(empty($res)){
            return failJson("修改前台信息失敗");
        }
        return sucessJson("修改前台信息成功");
    }



}
